package com.note.simpleshop.module.coupon.controller;

import com.note.simpleshop.constant.ErrorCode;
import com.note.simpleshop.exception.NotDataTypeException;
import com.note.simpleshop.module.coupon.dto.CouponDto;
import com.note.simpleshop.module.coupon.service.CouponService;
import com.note.simpleshop.module.coupon.vo.CouponVo;
import com.note.simpleshop.module.user.auth.RequestToken;
import com.note.simpleshop.module.user.auth.UserUtils;
import com.note.simpleshop.vo.Msg;
import com.note.simpleshop.vo.PageBean;
import io.swagger.annotations.*;
import net.bytebuddy.asm.Advice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/***
 *@ClaseName:MyCouponController
 *
 *@Decription:我的个人中心优惠劵
 *
 *@Author: xubingbing
 *
 *@Date:2019/3/9 0009 21:42
 */
@Api(value="优惠劵",tags = "我的优惠劵")
@RestController
@RequestMapping("coupon/me")
public class MeCouponController {
    @Autowired
    private CouponService couponService;
    @ApiOperation(value = "我的优惠劵", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header")})
    @PostMapping(value = "index")
    @RequestToken
    public Msg<PageBean<CouponVo>> index(CouponDto dto) {
        Msg msg=new Msg();
        try {
            dto.setUserId(UserUtils.currentUserId());
            PageBean<CouponVo> pageBean = couponService.findByPage(dto);
            msg.setErrorCode(ErrorCode.ERROR_0000);
            msg.setData(pageBean);
        } catch (NotDataTypeException e) {
            msg.setMsg(e.getMessage());
            msg.setErrorCode(ErrorCode.ERROR_1000000);
        }
        return msg;
    }
}
